(function(){
	var orgnTree = new Ext.tree.TreePanel({
		region : 'west',
		width : 200,
		iconCls : 'orgn',
		title : '组织结构',
		autoScroll : true,
		rootVisible : false,
		animate : false,
		border : false,
		split: true,
		collapsible : true,
		loader : new Ext.tree.TreeLoader({
			url : 'dept/dept_queryDepartmentTree.action'
		}),
		root : new Ext.tree.AsyncTreeNode({
			expanded : true,
			text : 'root',
			id : basicConstant.TREE_ROOT_ID
		}),
		tools : [{
			id : 'refresh',
			handler: function(){
				orgnTree.root.reload();
			}
		}]
	});
	
	orgnTree.on('click',function(node){
		departNo = node.attributes.id;
		alert(departNo);
		
	});
	_orgnGrid = Ext.extend(Ext.grid.GridPanel,{
		viewConfig : {
			forceFit : true
		},
		constructor : function(config){
			Ext.apply(this,config);
			this.sm = new Ext.grid.CheckboxSelectionModel({
				
			});
			this.cm = new Ext.grid.ColumnModel([
				this.sm,
				new Ext.grid.RowNumberer({
						header : '序号',
						width :  45,
						scope : this,
						renderer : function(value,metadata,record,rowIndex){
							return this.store.lastOptions.params.start+1+rowIndex;
						}
				}),
				{id : 'id' , header : 'ID',dataIndex : 'id', sortable:true,hidden : true},
				{header: '部门名称',dataIndex : 'name', sortable :true},
				{header: '业务对照码',dataIndex : 'businessNo',sortable : true},
				{header: '上级部门',dataIndex : 'parentName' ,sortable : true},
				{header: '排序号', dataIndex : 'orderIds' , sortable : true},
				{header: '部门编号', dataIndex : 'deptNo', sortable : true}
			]);
			this.tbar = {
				xtype : 'toolbar',
				items : [{
					iconCls: 'btnAdd',
					text : '新增',
					handler : this.addUser,
					scope : this
				},'-',{
					iconCls: 'btnModify',
					text : '修改',
					handler : this.modUser,
					scope : this
				},'-',{
					iconCls: 'btnDelete',
					text : '删除',
					handler : this.delUser,
					scope : this
				}]
			};
			this.store = new Ext.data.Store({
				proxy : new Ext.data.HttpProxy({
					url : 'dept/dept_queryDepartment.action'
				}),
				reader : new Ext.data.JsonReader({
					totalProperty : 'totalProperty',
					root : 'root',
					id : 'id'
				},[{
					name : 'id', mapping : 'id'
				},{
					name : 'name' , mapping : 'name'
				},{
					name : 'businessNo' , mapping : 'businessNo'
				},{
					name : 'parentName' , mapping : 'parentName'
				},{
					name : 'orderIds' , mapping : 'orderIds'
				},{
					name : 'deptNo' , mapping : 'deptNo'
				}])
			});
			this.store.load({params :{start :0,limit : 20}});
			this.bbar = new Ext.PagingToolbar({
				pageSize : basicConstant.PAGESIZE,
				store : this.store,
				displayInfo : true,
				plugins: new Ext.ux.plugins.PageComboResizer(),
				displayMsg : '显示第{0}条到 {1}条记录,共{2}条',
				emptyMsg : '没有记录'
			});
			_orgnGrid.superclass.constructor.call(this);
		},
		delUser :function(){
		
		},
		modUser : function(){
		
		},
		addUser : function(){
		
		}
	});
	return new Ext.Panel({
		draggable : false,
		closable : true,
		layout : 'border',
		items : [orgnTree, new _orgnGrid({region: 'center'})]
	});
})()